﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace test5
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        public delegate int MyDelegate(int x, int y);

        MyDelegate ptr = new MyDelegate(add);

        private void confirm_Click(object sender, EventArgs e)
        {
            if(input.Text.Length != 0)
            {
                int numI1 = (int)(input.Text[0] - '0');
                int numI2 = (int)(input.Text[2] - '0');
                int sumIA = 0;
                int sumIM = 0;
                if(Add.Checked == true)
                {
                    sumIA = add(numI1, numI2);
                }

                if(multiplication.Checked == true)
                {
                    sumIM = mul(numI1, numI2);
                }

                if(Add.Checked == false && multiplication.Checked == false)
                {
                    if (numI1 < 10 && numI2 < 10)
                    {
                        if(ptr != null)
                        {
                            int sum = ptr(numI1, numI2);
                            MessageBox.Show("因为两个数字均小于10    相加之后的结果是:  " + sum);
                        }
                    }
                    else
                    {
                        ptr = mul;
                        if (ptr != null)
                        {
                            int sum = ptr(numI1, numI2);
                            MessageBox.Show("因为两个数字不都小于10    相乘之后的结果是:  " + sum);
                        }
                    }
                }

                if(Add.Checked == true && multiplication.Checked == true)
                {
                    MessageBox.Show("相加之后的结果是:  " + sumIA + '\n' + "相乘之后的结果是: " + sumIM);
                }
                else if(Add.Checked == true)
                {
                    MessageBox.Show("相加之后的结果是:  " + sumIA);
                }
                else if(multiplication.Checked == true)
                {
                    MessageBox.Show("相乘之后的结果是:  " + sumIM);
                }
            }
            else if(textBox1.Text.Length != 0)
            {
                double numD1 = (double)(textBox1.Text[0] - '0');
                double numD2 = (double)(textBox1.Text[2] - '0');
                double sumDA = 0;
                double sumDM = 0;

                if (Add.Checked == true)
                {
                    sumDA = add(numD1, numD2);
                }

                if (multiplication.Checked == true)
                {
                    sumDM = mul(numD1, numD2);
                }

                if (Add.Checked == true && multiplication.Checked == true)
                {
                    MessageBox.Show("相加之后的结果是:  " + sumDA + '\n' + "相乘之后的结果是:  " + sumDM);
                }
                else if (Add.Checked == true)
                {
                    MessageBox.Show("相加之后的结果是:  " + sumDA);
                }
                else if (multiplication.Checked == true)
                {
                    MessageBox.Show("相乘之后的结果是:  " + sumDM);
                }
            }
            else
            {
                MessageBox.Show("请至少勾选一个计算方式");
            }
            input.Text = "";
            textBox1.Text = "";
    
        }

        private void input_TextChanged(object sender, EventArgs e)
        {

        }


        static public int add(int x, int y)
        {
            return x + y;
        }

        static public int mul(int x, int y)
        {
            return x * y;
        }

        static public double add(double x, double y)
        {
            return x + y;
        }

        static public double mul(double x, double y)
        {
            return x * y;
        }

        private void add_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void exit_Click(object sender, EventArgs e)
        {
            Application.Exit();

        }


    }
}
